import { EntityManager, MikroORM } from '@mikro-orm/mariadb';
import config from '../../../mikro-orm.config';

const em: EntityManager = {} as EntityManager;

export async function initORM() {
  // @ts-ignore
  if (global.orm) {
    // @ts-ignore
    return global.orm.em as typeof orm.em;
  }

  const orm = await MikroORM.init(config);

  // @ts-ignore
  global.orm = orm;

  return orm.em;
}
